<?php $this->load->view('common/default_header.php');?>
<?php $this->load->view('common/nav.php');?>
<section class="trade">
    <dl class="panels text-center">
        <dt>帐户余额</dt>
        <dd class="">￥<?php echo $user_info['cny'];?></dd>
        <div class="clear"></div>
    </dl>
    <div class="borbtm text-center padb20">
        <div class="pad010"><input class="form-control hm2" type="text" name="txAmount" id="txAmount" placeholder="请输入提现金额"/></div>
        <?php if(false){?><p class="red">您有免手续费资格（提现金额小于200）</p><?php }?>
        <p>提示：提现手续费每笔2元，提现成功后自动绑定银行卡</p>
        <p>提示：提现金额小于等于200元通过微信红包发放</p>
    </div>
    <div class="" style="padding: 0 10px;">
 <!--        <div class="check-type">
            <p><span class="checkbox_icon"></span>微信钱包付款（支持200元以内的充值）</p>
            <p><span class="checkbox_icon check-on"></span>微信钱包付款（支持200元以内的充值）</p>
        </div> -->
		<?php if(empty($bank)){?>
        <select class="form-control hm2 mb10" id="bank">
            <option selected="selected" value="">请选择银行</option>
        <?php if(!empty($bankArr)) foreach($bankArr as $code=>$bank){?>
            <option value="<?php echo $code;?>"><?php echo $bank;?></option>
        <?php }?>
        </select>
        <div id="city">
            <select class="prov form-control hm2 mb10" id="city_prov"></select>
            <select class="city form-control hm2 mb10" disabled="disabled" id="city_city">
                <option value=''>请选择城市</option>
            </select>
        </div>

        <input class="form-control hm2" type="text" name="bank_name" id="bank_name" placeholder="请输入开户行支行名称"/>
        <input class="form-control hm2" type="text" name="card_no" id="card_no" placeholder="请输入银行卡号"/>
        <input class="form-control hm2" type="text" name="card_name" id="card_name" placeholder="请输入持卡人姓名"/>
		<?php }else{?>
			<input class="form-control hm2" type="text" name="bank" id="bank"  disabled="disabled" value="<?php echo $bankArr[$bank['bank']]?>"/>
			<input class="form-control hm2" type="text" name="prov" id="city_prov" disabled="disabled" value="<?php echo $bank['prov']?>"/>
			<input class="form-control hm2" type="text" name="city" id="city_city" disabled="disabled" value="<?php echo $bank['city']?>"/>
			<input class="form-control hm2" type="text" name="bank_name" id="bank_name" disabled="disabled" value="<?php echo $bank['bank_name']?>"/>
			<input class="form-control hm2" type="text" name="card_no" id="card_no" disabled="disabled" value="<?php echo substr_replace($bank['card_no'],'****',4,8);?>"/>
			<input class="form-control hm2" type="text" name="card_name" id="card_name" disabled="disabled" value="<?php echo $bank['card_name']?>"/>
		<?php }?>
        <div class="reg-btn">
            <a href="javascript:withdraw();" class="btn btn-warning btn-lg btn-block" id="withdrawBtn">确认提现</a>
        </div>
        <div class="tj_tip">
            <p>提现至银行卡（提现金额小于200元将以微信红包形式发放），1个工作日内处理</p>
        </div>

    </div>
	<div style="display: none" id="withdrawBtnHtml"></div>
</section>

<script src="<?php echo js_url("/wcp/jquery-1.9.1.min.js"); ?>?20160329001" type="text/javascript"></script>
<script src="<?php echo js_url("/wcp/bootstrap.min.js"); ?>?20160329001" type="text/javascript"></script>
<script src="<?php echo js_url("/wcp/jquery.city.js"); ?>?20160329001" type="text/javascript"></script>
<script src="<?php echo js_url("/wcp/main.js"); ?>?20160329002" type="text/javascript"></script>
<script src="<?php echo js_url("/wcp/bootstrap-dialog.min.js"); ?>?20160329001" type="text/javascript"></script>

<script type="text/javascript">
$(function(){
    $("#city").citySelect({
        nodata:"none",
        required:false
    });
});

function withdraw(){
	var amount = $('#txAmount').val();
    if(amount<=0){
        myAlert("请输入提现金额");
        return;
    }
    if(amount<50){
        myAlert("提现金额不能少于50元");
        return;
    }
	var bank = $.trim($("#bank").val());
	if(bank==""){
		myAlert("请选择银行");
        return;
	}
	var prov = $.trim($("#city_prov").val());
	if(prov==""){
		myAlert("请选择省份");
        return;
	}
	var city = $.trim($("#city_city").val());
	if(city==""){
		myAlert("请选择城市");
        return;
	}
	var bank_name = $.trim($("#bank_name").val());
	if(bank_name==""){
		myAlert("请输入开户行支行名称");
        return;
	}
	var card_no = $.trim($("#card_no").val());
	if(card_no==""){
		myAlert("请输入银行卡号");
        return;
	}
	var card_name = $.trim($("#card_name").val());
	if(card_name==""){
		myAlert("请输入持卡人姓名");
        return;
	}
    var disable = $('#withdrawBtn').hasClass('disabled');
    if ((disable == false || disable == undefined)) {
        $('#withdrawBtn').addClass('disabled');
		$.ajax({
			type: 'POST',
			url: "/api/cny/withdraw",
			data: {'amount': amount,'bank':bank,'prov':prov,'city':city,'bank_name':bank_name,'card_no':card_no,'card_name':card_name} ,
			beforeSend: function(){
				$('#withdrawBtn').html('加载中...');
			},
			success: function(data){
                if(data.code==0){
                    myAlert('提现成功，将在1个工作日内处理！','success');
                    $('#withdrawBtn').removeClass('disabled');
                    $('#withdrawBtn').html('确认提现');
                }else{
                    myAlert(data.message);
                    $('#withdrawBtn').removeClass('disabled');
                    $('#withdrawBtn').html('确认提现');
                }
			}
		 });
	}
}

</script>

<?php $this->load->view('common/wx_share.php');?>
